#ifndef STLMAINWINDOW_H
#define STLMAINWINDOW_H

#include <memory>

#include <QDir>
#include <QMessageBox>
#include <QFileDialog>
#include <QVBoxLayout>

#include <QMainWindow>
#include "STLReader.h"

#include "stlmodelwidget.h"
#include "slicemainwindow.h"
#include "slicingsettingsdialog.h"
#include "previewdirectionselector.h"
#include "modelcolorpalette.h"
#include "snapshotsettingdialog.h"

namespace Ui {
class STLMainWindow;
}

class STLMainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit STLMainWindow(QWidget *parent = nullptr);
    ~STLMainWindow();

public:
    void iniUI();
    void updateUI();
    void initModelWidget();
    void createSlicingWindow(SliceInfo slice_info);
private:
    void handleSlicingSettings(const QVector3D& planeNormal, const QVector3D& cameraUp, float cameraDistance, float slicingStride);
    void updateCurrentFileLabel(const QString& stl_file_path);
signals:
    void sendAllContours(const QVector<QVector<QVector<QPointF>>>& all_contours);

private slots:
    void on_actionOpenSTL_triggered();
    void on_actionSliceModel_triggered();
    void on_actionSetupSliceInfo_triggered();
    void on_actionSaveAs_triggered();
    void on_actionPreview_triggered();
    void on_actionQuickSlicingSetting_triggered();
    void on_allContours_delivered(const QVector<QVector<QVector<QPointF>>>& all_contours);
    void on_actionModelColorSetting_triggered();
    void on_actionGrayScaleConvertion_triggered();
    void on_actionViewPortMatched_triggered();
    void on_actionViewPortFilled_triggered();

private:
    std::shared_ptr<STLReader> m_sp_stl_reader;
    std::shared_ptr<STLModelWidget> m_sp_modelWidget;
    std::shared_ptr<SliceMainWindow> m_sp_sliceWidget;
    std::shared_ptr<SlicingSettingsDialog> m_sp_slicingSettingDialog;
    std::shared_ptr<PreviewDirectionSelector> m_sp_previewDirectionSelector;
    std::shared_ptr<ModelColorPalette> m_sp_modelColorPalette;
    std::shared_ptr<SnapShotSettingDialog> m_sp_snapShotSetting;
    std::shared_ptr<STLModelWidget> snapshot_screen;

private:
    Ui::STLMainWindow *ui;
    QLabel *fLabCurFile;
};

#endif // STLMAINWINDOW_H
